<?php
class commentModel extends CI_Model{
	var $tbl = 'comments';
	
	public function getAllComments(){
		$this->db->select('*');
		$this->db->from('comments');
		$this->db->join('users','users.user_id=comments.user_id','inner');
		$this->db->order_by('date','desc');
		$q=$this->db->get();
		if($q->num_rows()>0){
			return $q->result();
		}
	}

        public function getCommentInfo($id){
            if(isset($id)&& !empty($id)){
                $this->db->where('comment_id',$id);
                $q=$this->db->get($this->tbl);
                if($q->num_rows()>0){
                    return $q->result();
                }
            }
        }

	public function addNewComment($data){
		if(isset($data) && array($data)){
		$this->db->insert($this->tbl,$data);
		return true;
		}
	}
	
	public function remove($id){
		if(isset($id) && !empty($id)){
			$this->db->where('comment_id',$id);
			$this->db->delete($this->tbl);
			return ($this->getCommentInfo($id)) ? false : true ;
		}
	}

        public function getLatest($id){
            if(isset($id) && !empty($id)){
                        $this->db->select('*');
                        $this->db->from('comments');
                        $this->db->join('users','users.user_id=comments.user_id','inner');
			$this->db->where('comments.user_id',$id);
                        $this->db->order_by('date','desc');
                        $this->db->limit(1);
			$q = $this->db->get();
                        return $q->result();
            }
        }
}